package com.zcx.merchantorder.util;

import android.content.Context;
import android.content.SharedPreferences;

import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @Description: SharedPreferences存储封装工具
 * @Author: zcx
 * @CreateDate: 2019/3/2 15:46
 */
public class SharedPreferencesUtil {

    private SharedPreferences preferences;
    private SharedPreferences.Editor editor;

    /**
     * @description 获取SharedPreferences初始化
     * @date: 2019/3/2 15:55
     * @author: zcx
     * @param context
     * @return void
     */
    public SharedPreferencesUtil(Context context) {
        preferences = context.getSharedPreferences("mysp", Context.MODE_PRIVATE);
        editor = preferences.edit();
    }

    /**
     * @description 存储boolean值
     * @date: 2019/3/2 15:56
     * @author: zcx
     * @param key
     * @param value
     * @return void
     */
    public void putBoolean(String key, boolean value) {
        editor.putBoolean(key, value).commit();
    }

    /**
     * @description 获取boolean的值
     * @date: 2019/3/2 15:57
     * @author: zcx
     * @param key
     * @param defaultValue
     * @return boolean
     */
    public  boolean getBoolean(String key, boolean defaultValue) {
       return preferences.getBoolean(key, defaultValue);
    }

    /**
     * @description 存储浮点型的值
     * @date: 2019/3/2 15:57
     * @author: zcx
     * @param key
     * @param value
     * @return void
     */
    public void putFloat(String key, float value) {
        editor.putFloat(key, value).commit();
    }

    /**
    * 获取浮点型的值
     * @date: 2019/3/2 15:58
     * @author: zcx
     * @param key
     * @param defaultValue
     * @return float
     */
    public float getFloat( String key, float defaultValue) {
        return preferences.getFloat(key, defaultValue);
    }

    /**
    *存储String类型的值
     * @date: 2019/3/2 15:58
     * @author: zcx
     * @param key
     * @param value
     * @return void
     */
    public void putString(String key, String value) {
        editor.putString(key, value).commit();
    }

    /**
    *获取String类型的值
     * @date: 2019/3/2 15:59
     * @author: zcx
     * @param key
     * @param defaultValue
     * @return java.lang.String
     */
    public String getString( String key, String defaultValue) {
        return preferences.getString(key, defaultValue);
    }

    /**
    *设置Long类型的值
     * @date: 2019/3/2 15:59
     * @author: zcx
     * @param key
     * @param value
     * @return void
     */
    public void putLong(String key, long value) {
        editor.putLong(key, value).commit();
    }

    /**
    *获取Long类型的值
     * @date: 2019/3/2 16:00
     * @author: zcx
     * @param key
     * @param defaultValue
     * @return long
     */
    public long getLong(String key, long defaultValue) {
        return preferences.getLong(key, defaultValue);
    }

    /**
    *设置int类型的值
     * @date: 2019/3/2 16:00
     * @author: zcx
     * @param key
     * @param value
     * @return void
     */
    public void putInt(String key, int value) {
        editor.putInt(key, value).commit();
    }

    /**
    *获取int类型的值
     * @date: 2019/3/2 16:01
     * @author: zcx
     * @param key
     * @param defaultValue
     * @return int
     */
    public int getInt(String key, int defaultValue) {
        return preferences.getInt(key, defaultValue);
    }
}
